package com.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

import com.dao.SaleOrderItemDAO;
import com.model.Customer;
import com.model.SaleOrderItem;
import com.util.DB;

public class SaleOrderItemDAOImpl implements SaleOrderItemDAO {
//	private Connection conn = DB.getConnection();
	private Connection conn = DB.con;
	@Override
	public boolean addSaleOrderItem(SaleOrderItem saleOrderItem) {
		// TODO Auto-generated method stub
		PreparedStatement st = null;
		try {
			int saleOrder_ID = saleOrderItem.getSaleOrder().getId();
			int product_ID = saleOrderItem.getProduct().getId();
			int quantity = saleOrderItem.getQuantity();
			double price = saleOrderItem.getPrice();

			st = conn
					.prepareStatement("insert into saleOrderItem(saleOrder_ID,product_ID,quantity,price) values(?,?,?,?)");
			st.setInt(1, saleOrder_ID);
			st.setInt(2, product_ID);
			st.setInt(3, quantity);
			st.setDouble(4, price);

			int num = st.executeUpdate();
			if (num > 0) {
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DB.close(st, null);
		}
		return false;
	}

	@Override
	public String selectSaleOrderItem(int page, int rows, String key,
			String type) {
		// TODO Auto-generated method stub
		return null;
	}

}
